// pages/selection/selection.js
import {carList} from '../../api/car.js'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    $https: getApp().globalData.$https,
    actIndex: 0,
    scrollLeft:0,
    tabList: [{
      id: 1,
      name: '微客',
    }],
    carList: []
  },
  tabClick(e) {
    var index = e.currentTarget.dataset.index;
    console.log(index)
    if(this.data.actIndex > index){
      if(index == 0){
        this.setData({
          scrollLeft:0
        })
      }else if(index == 1){
        this.setData({
          scrollLeft:0
        })
      }else if(index == 2){
        this.setData({
          scrollLeft:0
        })
      }else if(index == 3){
        this.setData({
          scrollLeft:160
        })
      }
    }else{
      if(index == 0){
        this.setData({
          scrollLeft:0
        })
      }else if(index == 1){
        this.setData({
          scrollLeft:0
        })
      }else if(index == 2){
        this.setData({
          scrollLeft:80
        })
      }else if(index == 3){
        this.setData({
          scrollLeft:160
        })
      }else if(index == 4){
        this.setData({
          scrollLeft:200
        })
      }
    }
    
    this.setData({
      actIndex: index
    })
    this.carDetails()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.carList()
  },
  zaixiankefu(){
    wx.navigateTo({
      url: '../customer/customer',
    })
  },
  async carList() {
    var res = await carList()
    this.setData({
      tabList: res.category
    })
    this.carDetails()
  },
  async carDetails() {
    var id = this.data.tabList[this.data.actIndex].id
    var res = await carList(id)
    this.setData({
      carList: res.list
    })
  },
  carDetail(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../carDetail/carDetail?id=' + id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})